package com.smmisia.redis.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;

import java.time.Duration;

@ConfigurationProperties(prefix = "redis")
public class RedisProperties {
    private boolean enabled = true;

    // Redis连接基础配置
    private String host = "localhost";
    private int port = 6378;
    private String password;
    private int database = 0;
    private Duration timeout = Duration.ofMillis(2000);

    // 连接池配置
    private Pool pool = new Pool();

    // 序列化配置
    private Serializer serializer = new Serializer();

    @Data
    public static class Pool {
        private int maxActive = 8;
        private int maxIdle = 8;
        private int minIdle = 0;
        private Duration maxWait = Duration.ofMillis(-1);
        private boolean testOnBorrow = false;
        private boolean testOnReturn = false;
        private boolean testWhileIdle = true;
    }

    @Data
    public static class Serializer {
        private boolean usePrefix = true;
        private String keyPrefix = "";
        private String dateFormat = "yyyy-MM-dd HH:mm:ss";
        // 是否写入类型信息，方便反序列化
        private boolean writeClassName = true;
    }

    // Getters and Setters
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public Duration getTimeout() {
        return timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    public Pool getPool() {
        return pool;
    }

    public void setPool(Pool pool) {
        this.pool = pool;
    }

    public Serializer getSerializer() {
        return serializer;
    }

    public void setSerializer(Serializer serializer) {
        this.serializer = serializer;
    }
}


